package com.ws.dao;

import com.ws.entity.SharedBike;
import com.ws.entity.SharedBikeCompany;
import com.ws.util.Menu;

import java.util.InputMismatchException;
import java.util.Scanner;

/**
 * @author 王硕
 */
public class BikeManager {
    public int i=3;
    public SharedBikeCompany[] sharedBikeCompany = new SharedBikeCompany[i];
    Scanner scanner = new Scanner(System.in);
    // 初始化添加单车公司和单车信息
    public void addData() {
        // OfO
        sharedBikeCompany[0] = new SharedBikeCompany();
        sharedBikeCompany[0].setBikeCompanyId(1);
        sharedBikeCompany[0].setBikeCompanyName("OfO");
        sharedBikeCompany[0].setSharedBikes(new SharedBike[3]);
        sharedBikeCompany[0].setSum(10);
        sharedBikeCompany[0].setCount(100);
        // 添加单车到OfO
        SharedBike[] ofoBikes = new SharedBike[3];
        ofoBikes[0] = SharedBike.createBike(1, "OfO单车1", 1);
        ofoBikes[1] = SharedBike.createBike(2, "OfO单车2", 0);
        ofoBikes[2] = SharedBike.createBike(3, "OfO单车3", 1);
        sharedBikeCompany[0].setSharedBikes(ofoBikes);

        // Hello
        sharedBikeCompany[1] = new SharedBikeCompany();
        sharedBikeCompany[1].setBikeCompanyId(2);
        sharedBikeCompany[1].setBikeCompanyName("Hello");
        sharedBikeCompany[1].setSharedBikes(new SharedBike[3]);
        sharedBikeCompany[1].setSum(10);
        sharedBikeCompany[1].setCount(100);
        // 添加单车到Hello
        SharedBike[] helloBikes = new SharedBike[3];
        helloBikes[0] = SharedBike.createBike(1, "Hello单车1", 1);
        helloBikes[1] = SharedBike.createBike(2, "Hello单车2", 0);
        helloBikes[2] = SharedBike.createBike(3, "Hello单车3", 1);
        sharedBikeCompany[1].setSharedBikes(helloBikes);

        // 青桔
        sharedBikeCompany[2] = new SharedBikeCompany();
        sharedBikeCompany[2].setBikeCompanyId(3);
        sharedBikeCompany[2].setBikeCompanyName("青桔");
        sharedBikeCompany[2].setSharedBikes(new SharedBike[3]);
        sharedBikeCompany[2].setSum(10);
        sharedBikeCompany[2].setCount(100);
        // 添加单车到青桔
        SharedBike[] qingJuBikes = new SharedBike[3];
        qingJuBikes[0] = SharedBike.createBike(1, "青桔单车1", 1);
        qingJuBikes[1] = SharedBike.createBike(2, "青桔单车2", 0);
        qingJuBikes[2] = SharedBike.createBike(3, "青桔单车3", 1);
        sharedBikeCompany[2].setSharedBikes(qingJuBikes);
    }

    // 打印单车公司和单车信息
    public void viewBike(SharedBikeCompany[] companies) {
        for (int i = 0; i < sharedBikeCompany.length; i++) {
            SharedBikeCompany company = sharedBikeCompany[i];
            if (company != null) {
                // 打印公司信息
                System.out.println("-----------------------------------------------");
                System.out.println("|公司序号 | 公司名称 | 公司单车数量 | 公司单车借出次数|");
                System.out.println("-----------------------------------------------");
                System.out.println("|" + (i + 1) + " \t\t| " + company.getBikeCompanyName() + " \t | " + company.getSum() + " \t\t| " + company.getCount());
                // 打印单车信息
                for (int j = 0; j < company.getSharedBikes().length; j++) {
                    // 打印单车信息的表头
                    System.out.println("单车序号 | 单车品牌 | 单车状态 | 借出时间");
                    System.out.println("-----------------------------------------------");
                    SharedBike bike = company.getSharedBikes()[j];
                    if (bike != null) {
                        String status = bike.getStatus() == 1 ? "可借" : "已借出";
                        System.out.println("" + (j + 1) + " \t| " + bike.getBname() + " \t| " + status + " \t| " + bike.getBorrowTime());
                        System.out.println("-----------------------------------------------");
                    }
                }
            }
        }
    }

    public void dropBike(SharedBikeCompany[] companies) {
        SharedBikeCompany ofOcompany = sharedBikeCompany[0];
        SharedBikeCompany hellocompany = sharedBikeCompany[1];
        SharedBikeCompany qingjucompany = sharedBikeCompany[2];
        while (true) {
            System.out.println("1——"+ofOcompany.getBikeCompanyName());
            System.out.println("2——"+hellocompany.getBikeCompanyName());
            System.out.println("3——"+qingjucompany.getBikeCompanyName());
            System.out.println("请选择你要投放的单车:");
            try {
                int i = scanner.nextInt();
                switch (i) {
                    case 1:

                        break;
                    case 2:
                        System.out.println(3);
                        break;
                    case 3:
                        System.out.println(3);
                        break;
                    default:
                        System.out.println("你输入的数据错误");
                        break;
                }
            } catch (InputMismatchException e) {
                System.out.println("请输入数字");
                scanner.next();
            }
            Menu.returnMain(scanner);
        }
    }

    public void deleteBike() {

    }

    public void loanBike() {
    }

    public void returnBike() {
    }

    public void bikeranking() {
    }
}